import {
  Column,
  Entity,
  OneToMany,
  Tree,
  TreeChildren,
  TreeParent,
} from 'typeorm';
import { DBColumns } from '../';
import { ArticleCategorySchema, ArticleSchema } from '../../schema';
import { Article } from '../article/article';

@Entity('article_category')
@Tree('closure-table')
export class ArticleCategory
  extends DBColumns
  implements ArticleCategorySchema
{
  @Column({
    type: 'varchar',
    length: 50,
    nullable: false,
    default: null,
    comment: '文章分类名称',
  })
  categoryName: string;

  @Column({
    type: 'varchar',
    length: 50,
    nullable: false,
    default: null,
    comment: '文章分类编码',
  })
  categoryCode: string;

  @TreeParent()
  parent?: ArticleCategorySchema;

  @TreeChildren()
  children?: ArticleCategorySchema[];

  @OneToMany(() => Article, article => article.category)
  articles?: ArticleSchema[];
}
